package fm.entity;

import fm.util.DateUtils;

import javax.persistence.*;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "section_pay_resolve", schema = "neiyi", catalog = "")
public class SectionPayResolve {
    private long id;
    private String type;
    private BigDecimal oneDay;
    private BigDecimal oneWeek;
    private BigDecimal oneMonth;
    private BigDecimal threeMonth;
    private BigDecimal halfYear;
    private BigDecimal year;
    private Long sectionId;


    public SectionPayResolve() {
    }

    public SectionPayResolve(String type) {
        this.type = type;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Basic
    @Column(name = "type")
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Basic
    @Column(name = "one_day")
    public BigDecimal getOneDay() {
        return oneDay;
    }

    public void setOneDay(BigDecimal oneDay) {
        this.oneDay = oneDay;
    }

    @Basic
    @Column(name = "one_week")
    public BigDecimal getOneWeek() {
        return oneWeek;
    }

    public void setOneWeek(BigDecimal oneWeek) {
        this.oneWeek = oneWeek;
    }

    @Basic
    @Column(name = "one_month")
    public BigDecimal getOneMonth() {
        return oneMonth;
    }

    public void setOneMonth(BigDecimal oneMonth) {
        this.oneMonth = oneMonth;
    }

    @Basic
    @Column(name = "three_month")
    public BigDecimal getThreeMonth() {
        return threeMonth;
    }

    public void setThreeMonth(BigDecimal threeMonth) {
        this.threeMonth = threeMonth;
    }

    @Basic
    @Column(name = "half_year")
    public BigDecimal getHalfYear() {
        return halfYear;
    }

    public void setHalfYear(BigDecimal halfYear) {
        this.halfYear = halfYear;
    }

    @Basic
    @Column(name = "year")
    public BigDecimal getYear() {
        return year;
    }

    public void setYear(BigDecimal year) {
        this.year = year;
    }

    @Basic
    @Column(name = "section_id")
    public Long getSectionId() {
        return sectionId;
    }

    public void setSectionId(Long sectionId) {
        this.sectionId = sectionId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SectionPayResolve that = (SectionPayResolve) o;

        if (id != that.id) return false;
        if (type != null ? !type.equals(that.type) : that.type != null) return false;
        if (oneDay != null ? !oneDay.equals(that.oneDay) : that.oneDay != null) return false;
        if (oneWeek != null ? !oneWeek.equals(that.oneWeek) : that.oneWeek != null) return false;
        if (oneMonth != null ? !oneMonth.equals(that.oneMonth) : that.oneMonth != null) return false;
        if (threeMonth != null ? !threeMonth.equals(that.threeMonth) : that.threeMonth != null) return false;
        if (halfYear != null ? !halfYear.equals(that.halfYear) : that.halfYear != null) return false;
        if (year != null ? !year.equals(that.year) : that.year != null) return false;
        if (sectionId != null ? !sectionId.equals(that.sectionId) : that.sectionId != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = (int) (id ^ (id >>> 32));
        result = 31 * result + (type != null ? type.hashCode() : 0);
        result = 31 * result + (oneDay != null ? oneDay.hashCode() : 0);
        result = 31 * result + (oneWeek != null ? oneWeek.hashCode() : 0);
        result = 31 * result + (oneMonth != null ? oneMonth.hashCode() : 0);
        result = 31 * result + (threeMonth != null ? threeMonth.hashCode() : 0);
        result = 31 * result + (halfYear != null ? halfYear.hashCode() : 0);
        result = 31 * result + (year != null ? year.hashCode() : 0);
        result = 31 * result + (sectionId != null ? sectionId.hashCode() : 0);
        return result;
    }


    public BigDecimal getPrice(String key) throws Exception {
        Field field = this.getClass().getDeclaredField(key);//根据变量名m获得字段
        field.setAccessible(true);//设置字段可访问，即暴力反射
        BigDecimal price = (BigDecimal) field.get(this);//在那个对象上获取此字段的值
        return price;
    }


    public static String getStartTime(String key) {
        return DateUtils.formatDateTime(new Date());


    }

    public static String getEndTime(String key) {
        switch (key) {
            case "oneWeek":
                return DateUtils.formatDateTime(DateUtils.addDay(new Date(), 7));

            case "oneMonth":
                return DateUtils.formatDateTime(DateUtils.addMonth(new Date(), 1));


            case "threeMonth":
                return DateUtils.formatDateTime(DateUtils.addMonth(new Date(), 3));


            case "halfYear":
                return DateUtils.formatDateTime(DateUtils.addMonth(new Date(), 6));


            case "year":
                return DateUtils.formatDateTime(DateUtils.addYear(new Date(), 1));


            case "oneDay":
                return DateUtils.formatDateTime(DateUtils.addDay(new Date(), 1));

            default:
                return null;

        }
    }
}
